﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using NetCoreCMS.Common;
using NetCoreCMS.IServices;

namespace NetCoreCMS.Web.Areas.Admin.Controllers
{
    public class CenterController : ManageController
    {
        public IUsersService _users { get; set; }
        public IOrdersService _orders { get; set; }
        public IApplyService _apply { get; set; }
        public IShop_ApplyService _shop_apply { get; set; }
        public IActionResult Index()
        {
            ViewData["config"] = sysConfig;
            var admin_info = GetAdminInfo();//管理员信息
                                                            //登录信息
            if (admin_info != null)
            {
                var model1 = _manager_log.GetModel(admin_info.user_name, 1, CMSEnums.ActionEnum.Login.ToString());
                if (model1 != null)
                {
                    //本次登录
                    ViewBag.litIP = model1.user_ip;
                }
                var model2 = _manager_log.GetModel(admin_info.user_name, 2, CMSEnums.ActionEnum.Login.ToString());
                if (model2 != null)
                {
                    //上一次登录
                    ViewBag.litBackIP = model2.user_ip;
                    ViewBag.litBackTime = model2.add_time.ToString();
                }
            }
            ViewBag.普通会员 = _users.GetList("where user_id=0").Count;
            ViewBag.分销会员 = _users.GetList("where user_id>0").Count;
            ViewBag.未发货订单 = _orders.GetList(1, 1000, "where payment_status=2 and express_status=1 and status<3", "id asc").Count;
            ViewBag.未付款订单 = _orders.GetList(1, 1000, "where payment_status<2 and status<3", "id asc").Count;
            ViewBag.商家提现 = _shop_apply.GetList(1,1000, "where send_cancel=0", "id asc").Count;
            ViewBag.会员提现 = _apply.GetList(1, 1000, "where send_cancel=0", "id asc").Count;
            return View("~/Areas/admin/Views/Center.cshtml");
        }
    }
}